#ifndef TRANSFORMERCONTENT_ASSISTENT_HPP_3
#define TRANSFORMERCONTENT_ASSISTENT_HPP_3

#include <unistd.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include "transContentDefine.h"


class TransContentAssis{
	public:
	/**************************************
	 * convert the node from localhost byte order to network byte order
	 * the parameter must not be null
	 * @param [in,out] node: the localhost byte order device node
	 * ************************************/
	 static void NodeAddrL2N(NodeAddr* node){
		 NodeAddr _tempAddr = *node;
		 _tempAddr.half_value[0] = htonl(_tempAddr.half_value[0]);
		 _tempAddr.half_value[1] = htonl(_tempAddr.half_value[1]);
		 *node = _tempAddr;
	 }
	
	/**************************************
	 * convert the node from network byte order to localhost byte order
	 * the parameter must not be null
	 * @param [in,out] node: the network byte order device node
	 * ************************************/
	 static void NodeAddrN2L(NodeAddr* node){
		 NodeAddr _tempAddr = *node;
		 _tempAddr.half_value[0] = ntohl(_tempAddr.half_value[0]);
		 _tempAddr.half_value[1] = ntohl(_tempAddr.half_value[1]);
		 *node = _tempAddr;
	 }

	 static int INTL2N(int port){
		 return htonl(port);
	 }
	
	 static int INTN2L(int port){
		 return ntohl(port);
	 }
	
	 static short SHORTL2N(short value){
		 return htons(value);
	 }
	
	 static short SHORTN2L(short value){
		 return ntohs(value);
	 }
	 
	 static timespec TimeTp2Ts(int second){
		 timespec ts;
		 timeval tp;
		 gettimeofday(&tp, NULL);
		 ts.tv_sec = tp.tv_sec;
		 ts.tv_nsec = tp.tv_usec * 1000;
		 ts.tv_sec += (unsigned int)second;
		 return ts;
	 }
};
#endif //TRANSFORMERCONTENT_ASSISTENT_HPP_3
